<!DOCTYPE html> 
<html lang="ja"> 
    <head> 
        <meta charset="utf-8"> 
        <title>Number を拡張して色を扱えるようにする方法</title>
        
        <script>
            
            (function(){
                Number.prototype.getA = function() {
                    // ここキモ
                    return (this & 0xff000000) >>> 24;
                };
                Number.prototype.getR = function() {
                    return (this & 0xff0000) >> 16;
                };
                Number.prototype.getG = function() {
                    return (this & 0xff00) >> 8;
                };
                Number.prototype.getB = function() {
                    return (this & 0xff);
                };
                Number.prototype.toCSSValueRGB = function() {
                    return "rgb("+ this.getR() +","+ this.getG() +","+ this.getB() +")";
                };
                Number.prototype.toCSSValueRGBA = function() {
                    return "rgba("+ this.getR() +","+ this.getG() +","+ this.getB() +","+ this.getA() +")";
                };
            })();
            
            window.onload = function() {
                var white = 0xffffffff;
                console.group("white");
                console.log(white.toCSSValueRGB()); // rgb(255,255,255)
                console.log(white.toCSSValueRGBA());// rgba(255,255,255,255)
                console.groupEnd();
                
                var red = 0xf0ff0000;
                console.group("red");
                console.log(red.toCSSValueRGB());   // rgb(255,0,0)
                console.log(red.toCSSValueRGBA());  // rgba(255,0,0,240)
                console.groupEnd();
                
                var green = 0x0f00ff00;
                console.group("green");
                console.log(green.toCSSValueRGB());   // rgb(0,255,0)
                console.log(green.toCSSValueRGBA());  // rgba(0,255,0,15)
                console.groupEnd();
                
                var blue = 0x000000ff;
                console.group("blue");
                console.log(blue.toCSSValueRGB());   // rgb(0,0,255)
                console.log(blue.toCSSValueRGBA());  // rgba(0,0,255,0)
                console.groupEnd();
            };
            
        </script>

    </head>
    
    <body>
        <h1>Number を拡張して色を扱えるようにする方法</h1>
    </body>
</html>